#include"../inc/Address.h"
#include<iostream>
#include<string.h>

namespace http_server
{
Address::Address(const size_t port)
{
    ::memset(&_addr, 0, sizeof(_addr));
    _addr.sin_family = AF_INET;
    _addr.sin_port = htons(port);
    _addr.sin_addr.s_addr = htonl(INADDR_ANY);
}

Address::Address(const string& ip, const size_t port)
{
    ::memset(&_addr, 0, sizeof(_addr));
    _addr.sin_family = AF_INET;
    _addr.sin_port = htons(port);
    _addr.sin_addr.s_addr = inet_addr(ip.c_str());
}

Address::Address(const sockaddr_in& addr)
{
    _addr = addr;
}

sockaddr_in* Address::getInetAddr()
{
    return &_addr;
}

string Address::getIP() const
{
    return string(inet_ntoa(_addr.sin_addr));
}

size_t Address::getPort() const
{
    return ntohs(_addr.sin_port);
}
    
} // namespace http_server